Helpful Information
 
 
Category: Regex Programming
Finding "Strings" (enclosed by quoetes) using RegEx

Hello All,

I am trying to find all strings (enclosed by quotes) using a regular expression.

My first attempt was:
".*"

But that was too greedy...

So my second attempt was:
"[^"]*"

... which seemed to work... until I realized that it failed for escaped strings...

so I am trying to make a regular expression that will handle this case:

" my cool expression handles \"escaped quotes\" too!"

AWESOME IDEA UPDATE: I could have my regular expression look for \\" OR ^". How could I do that?

AWESOME ANSWER UPDATE: I found my answer...
"(\\"|[^"])*" seems to work... Just letting you know incase someone else has the same problem.

Thanks!

But what happens if you want to escape the '\'?
Like this:

Hi, "first an escape \" and this is a backslash: \\", and we're outside the quotes again.










privacy (GDPR)